package me.ezitku.base.extensions

import androidx.viewpager.widget.ViewPager


fun ViewPager.pageChange(action: SPageChangeListener.() -> Unit) = addOnPageChangeListener(SPageChangeListener().apply(action))

class SPageChangeListener : ViewPager.OnPageChangeListener {
    private var _onPageSelected: ((position: Int) -> Unit)? = null

    override fun onPageScrollStateChanged(state: Int) {

    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

    }

    override fun onPageSelected(position: Int) {
        _onPageSelected?.invoke(position)
    }

    fun onPageSelected(listener: (Int) -> Unit) {
        _onPageSelected = listener
    }


}